//
//  NSString+Date.m
//  KaiXinJingPai
//
//  Created by liu xiwang on 2018/1/18.
//  Copyright © 2018年 canfu. All rights reserved.
//

#import "NSString+Date.h"

@implementation NSString (Date)
+ (NSString *)getTotalTimeWithSeconds:(NSInteger)seconds{
    NSTimeInterval value = seconds;
    //计算具体的天，时，分，秒
    int second = (int)value %60;//秒
    int minute = (int)value / 60 % 60;
    int house = (int)((int)value % (24 * 3600)) / 3600;
    int day = (int)value / (24 * 3600);
    //将获取的int数据重新转换成字符串
    NSString *str;
    if (day != 0) {
        str = [NSString stringWithFormat:@"%d天%d小时%d分%d秒",day,house,minute,second];
    }else if (day==0 && house != 0) {
        str = [NSString stringWithFormat:@"%d小时%d分%d秒",house,minute,second];
    }else if (day== 0 && house== 0 && minute!=0) {
        str = [NSString stringWithFormat:@"%d分%d秒",minute,second];
    }else{
        str = [NSString stringWithFormat:@"%d秒",second];
    }
    //返回string类型的总时长
    return str;
}
@end
